const { User } = require("../../model/User")

module.exports = async (req, res) => {
    req.app.locals.currentLink = 'user';
    let {page = 1, pagesize = 10} = req.query;
    // 总数
    let count = await User.countDocuments({})
    // 总页数
    let total = Math.ceil(count / pagesize)
    // 页码对应的数据查询开始位置
    let start = (page - 1) * pagesize
    // 将用户从数据库中查询出来    
    let users = await User.find({}).limit(pagesize).skip(start);
    res.render('admin/user', {users: users, total: total, page: page})
}